package com.sqrj.phoneorder.service;

import com.sqrj.phoneorder.common.ServerResponse;
import com.sqrj.phoneorder.dao.WxHntRWDMapper;
import com.sqrj.phoneorder.model.SendChart;
import com.sqrj.phoneorder.model.WxHntRWD;
import com.sqrj.phoneorder.util.DateTimeUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
//混凝土任务单
@Service
public class WxHntRwdService {

    @Resource
    private WxHntRWDMapper wxHntRWDMapper;

//    public ServerResponse addWxSjRwd(WxHntRWD wxHntRWD) {
//
//       int resultCount =  wxSJRWDMapper.insertSelective(wxSJRWD);
////        int resultCount = wxOrderUnitMapper.delWxUnitByid(wxid,id);
//        if(resultCount > 0){
//            System.out.println("---------1-2--------------------");
//            return ServerResponse.createBySuccessMessage("增加任务单成功");
//        }
//        return ServerResponse.createByErrorMessage("增加任务单失败");
//    }


//    public List<WxSJRWD> queryWxSJRWDbyStatus(Integer status) {
//        return wxSJRWDMapper.queryWxSJRWDbyStatus(status);
//    }
//  查询单位订单走势图表数据
    public List<SendChart> querySendChart(String unitName) {
        return wxHntRWDMapper.querySendChart(unitName);
    }
//  增加任务单
    public ServerResponse addWxHntRWD(WxHntRWD wxHntRWD) {
        String orderNo = this.generateorderConno();
        wxHntRWD.setOrderConno(orderNo);

        int resultCount =  wxHntRWDMapper.insertSelective(wxHntRWD);
//        int resultCount = wxOrderUnitMapper.delWxUnitByid(wxid,id);
        if(resultCount > 0){
            return ServerResponse.createBySuccessMessage("增加任务单成功");
        }
        return ServerResponse.createByErrorMessage("增加任务单失败");
    }
//  生成任务单编号
    private String generateorderConno(){
        long currentTime = System.currentTimeMillis();
        Date d = new Date();
        String dd = DateTimeUtil.dateToStr(new Date(),"yyMMddHHmmss");
        int sjs = (int)(Math.random()*1000);
        System.out.println("-----------currentTime-----------------"+currentTime+"-----dd-----"+dd+"------c1000----"+sjs);
        return dd+String.format("%03d",sjs );
    }
//  查询混凝土任务单（状态）
    public List<WxHntRWD> queryWxHntRWDbyStatus(Integer status,String unitName) {
        return wxHntRWDMapper.queryWxHntRWDbyStatus(status,unitName);
    }
//  查询单位名称集合
    public List<String> queryWxUnitsByCode(String wxUserCode, Integer status,String date, String date1) {
        return wxHntRWDMapper.queryWxUnitsByCode(wxUserCode,status,date,date1);
    }
//  根据用户查询图表走势分析数据
    public List<SendChart> querySendChartbyCode(String wxUserCode) {
        return wxHntRWDMapper.querySendChartbyCode(wxUserCode);
    }
//  根据单位查询混凝土任务单
    public List<WxHntRWD> queryWxHntRWDbyUnit(String code, Integer status, String unitName, String date, String date1) {
        return wxHntRWDMapper.queryWxHntRWDbyUnit(code,status,unitName,date,date1);
    }
}
